CMAKE_MINIMUM_REQUIRED(VERSION 3.18)

INCLUDE("${CMAKE_SOURCE_DIR}/cmake/StringifyKernelFiles.cmake")
StringifyKernelFiles(
# INPUT
  "${CMAKE_CURRENT_SOURCE_DIR}/src/kernels" CudaCallbackPyKernelSources
# OUPUT
  PROJECT_CUDA_FILE_DECLARATIONS PROJECT_CUDA_FILE_DEFINITIONS)
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/src/CudaCallbackPyKernelSources.h.in" src/CudaCallbackPyKernelSources.h)
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/src/CudaCallbackPyKernelSources.cpp.in" src/CudaCallbackPyKernelSources.cpp)
FIND_LIBRARY(LIB_OMMCUDA REQUIRED
NAMES
  OpenMMCUDA
PATHS
  "${OPENMM_DIR}/lib/plugins"
)

SET(srcLocal
  src/CudaCallbackPyKernelFactory.cpp
  src/CudaNumPyKernels.cpp
  # generated by CONFIGURE_FILE()
  "${CMAKE_CURRENT_BINARY_DIR}/src/CudaCallbackPyKernelSources.cpp"
)
IF(COMPILE_TORCH_FORCE)
  LIST(APPEND srcLocal
    src/CudaTorchKernels.cpp
  )
ENDIF()

SET(libLocal libCuda)
ADD_LIBRARY("${libLocal}"
SHARED
  ${srcLocal}
)
SET_TARGET_PROPERTIES("${libLocal}"
PROPERTIES
  OUTPUT_NAME "${LIB_NAME}_CUDA"
)
INSTALL(TARGETS "${libLocal}"
LIBRARY
  DESTINATION lib/plugins
)
TARGET_LINK_LIBRARIES("${libLocal}"
PUBLIC
  libAPI
  ${LIB_OMMCUDA}
  CUDA::cudart
)
TARGET_INCLUDE_DIRECTORIES("${libLocal}"
PRIVATE
  "${CMAKE_CURRENT_BINARY_DIR}/src"
  "${CMAKE_SOURCE_DIR}/platforms/common/include"
)

INCLUDE("${CMAKE_SOURCE_DIR}/cmake/CommonDirsAndLibs.cmake")
